hysop.simulation module

Description of the simulation parameters (time, iteration …)

Usage

# Initialize the simulation
s = Simulation(start=0.2, end=1., time_step=0.1)
# do some initialisation stuff with operators,
# print(initial state ...)

# time loop
s.initialize() # --> ready to start
while not s.is_over:
    # operators work
    op.apply(s)
    io.apply(s)
    ...
    # update time step (optional)
    adapt_time.apply(s)

    # Prepare next step
    s.advance()

# end simulation (optional) to prepare io
s.finalize()
io.apply(s)
class hysop.simulation.Simulation(name=None, start=0.0, end=1.0, nb_iter=None, dt0=None, max_iter=None, t=None, dt=None, times_of_interest=None, mpi_params=None, quiet=False, clamp_t_to_end=True, restart=0, **kwds)[source]

Bases: object

Time-Simulation process description (time step, iteration …)

Parameters:
  • name (str, optional) – Name of this simulation.

  • start (real, optional) – Initial and final time for simulation.

  • end (real, optional) – Initial and final time for simulation.

  • nb_iter (int, optional) – Number of iterations required.

  • dt0 (real, optional) – Initial time step.

  • dt (ScalarParameter, optional) – ScalarParameter that will be used as time step. Cannot be a constant parameter.

  • t (ScalarParameter, optional) – ScalarParameter that will be used as time. Cannot be a constant parameter.

  • max_iter (int, optional) – Maximum number of iterations allowed. Defaults to 1e9.

  • times_of_interest (array-like of float) – List of times ti where the simulation may modify current timestep to get t=ti. Mainly used by HDF_Writers for precise time dependent dumping. tstart < ti <= tend Defaults to empty set.

  • clamp_t_to_end (bool, optional) – Specify if Simulation adjst dt for last iteration to have t=end

  • restart (int, optional) – Iteration number to start from.

time

current time (value at the end of the time step)

Type:

real

current_iteration

start at 0. See notes below.

Type:

int

is_over

true if end or max_iter or nb_iter has been reached.

Type:

bool

dt

The scalar parameter that may be updated.

Type:

hysop.parameter.scalar_parameter.ScalarParameter

t

The scalar parameter that represents time.

Type:

hysop.parameter.scalar_parameter.ScalarParameter

time_step

Value of the dt parameter.

Type:

double

time_of_interest

Current simulation time target.

Type:

float

Notes

  • all parameters are optional but either dt0 or nb_iter must be set.

  • If both dt0 and nb_iter are given, dt0 is not used.

  • current_iteration = -1 means simulation has not started, and self.time = self.start

  • current_iteration = 0 after a call to initialize, self.time = self.start + self.time_step, i.e. targeted time.

  • self.current_iteration = k, runs between self.t and self.tkp1. with self.tkp1 == self.time

advance(dbg=None, plot_freq=10)[source]

Proceed to next time.

  • Advance time and iteration number.

  • Compute the new timestep

  • check if simulation is over.

finalize()[source]

Use this function when you need to call an hdf i/o operator after the end of the time-loop.

initialize()[source]

(Re)set simulation to initial values –> back to iteration 0 and ready to run.

load_checkpoint(datagroup, mpi_params, io_params, relax_constraints)[source]
next_time_of_interest()[source]
print_state(verbose=None)[source]

Print current simulation parameters

save_checkpoint(datagroup, mpi_params, io_params, compressor)[source]
property time_step

Get current timestep.

update_time(t)[source]
update_time_step(dt)[source]

Update time step for the next iteration

Parameters:

dt (double) – the new time step

Notes

Warning : since it does not update tkp1 and time, it must be called at the end of the time loop, just before ‘advance’.

write_parameters(*params, **kwds)[source]